package LeetCode.month03.day86;

/**
 * @author 16778
 * @date 2025/10/26 20:26
 * @description
 */
public class No2043 {

}
class Bank {
    private long[] balance;

    public Bank(long[] balance) {
        this.balance = balance;
    }

    public boolean transfer(int account1, int account2, long money) {
        if(!withdraw(account1,money)) return false;
        if(!deposit(account2,money)) {
            deposit(account1,money);
            return false;
        }
        return true;
    }

    public boolean deposit(int account, long money) {
        if(account>balance.length) return false;
        balance[account-1]+=money;
        return true;
    }

    public boolean withdraw(int account, long money) {
        if(account>balance.length||balance[account-1]<money) return false;
        balance[account-1]-=money;
        return true;
    }
}
